from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from typing import List
from db import get_db
from models.user_feedback import UserFeedback
from schemas.feedback import FeedbackCreate, FeedbackOut

router = APIRouter()


@router.get("/", response_model=List[FeedbackOut])
def list_feedback(db: Session = Depends(get_db)):
    return db.query(UserFeedback).order_by(UserFeedback.id.desc()).limit(200).all()


@router.post("/", response_model=FeedbackOut)
def create_feedback(data: FeedbackCreate, db: Session = Depends(get_db)):
    fb = UserFeedback(**data.dict())
    db.add(fb)
    db.commit()
    db.refresh(fb)
    return fb








